<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FirmProfession;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FirmProfessionController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new FirmProfession(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('sort');
            $grid->column('name');
            $grid->column('status')
                ->using([0 => '隐藏',1 => '显示'])
                ->label([0 => 'danger',1 => 'success']);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('name')->width(3);

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FirmProfession(), function (Show $show) {
            $show->field('id');
            $show->field('sort');
            $show->field('name');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new FirmProfession(), function (Form $form) {
            $form->display('id');
            $form->number('sort')
                 ->help('数字越小,越靠前显示')
                 ->required();
            $form->text('name')
                ->maxLength(100)
                ->required();
            $form->radio('status')
                ->options([1 => '显示',0 => '隐藏'])
                ->default(1)
                ->required();

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
